﻿@using Website.Models
@model Website.Models.ViewModels.LogView
@{
    ViewBag.Title = "Log Resultater";
    Layout = "~/Views/_Shared/_Layout.cshtml";
    var userId = this.ViewData["UserID"] as Guid? ?? Guid.Empty;
    var happenedAfter = this.ViewData["After"] as DateTime?;
    var happenedBefore = this.ViewData["Before"] as DateTime?;
}

<h2>@ViewBag.Title</h2>

<fieldset class="searchCriterias">
    <legend>Søgning</legend>
    <table>    

        @if(userId != null && userId != Guid.Empty){
            <tr>
                <td>Bruger:</td>
                <td>
                    @if(Model.AllUsers.Any(x => x.ID == userId))
                    {
                        @Model.AllUsers.Single(x => x.ID == userId).Name
                    }
                </td>
            </tr>  
        }
        @if(happenedAfter.HasValue && happenedAfter.Value > new DateTime(2000, 01, 01))
        {
            <tr>
                <td>Fra:</td><td>@happenedAfter.Value.ToShortDateString()</td>
            </tr>  
        }
        @if (happenedBefore.HasValue && happenedBefore.Value > new DateTime(2000, 01, 01))
        {
            <tr>
                <td>Til:</td><td>@happenedBefore.Value.ToShortDateString()</td>
            </tr>  
        }
    </table>

</fieldset>

<table class="logTable">
    <tr>
        <td>Tidspunkt</td>
        <td>Beskrivelse</td>
        <td>Type</td>
        <td>Objekt</td>
    </tr>
    @foreach (var logEntry in Model.List)
    {
        <tr>
            <td>@logEntry.Timestamp.ToShortDateString()</td>
            <td>@logEntry.Text</td>
            <td>@logEntry.ActionTypeName</td>
            <td>@logEntry.ObjectTypeName</td>
        </tr>
    }
    
</table>